<!DOCTYPE html>
<html>
    
    <head>
       <meta charset="UTF-8">
        {include="style"}
		<link rel="stylesheet" type="text/css" href="{__Tpl_style__}/style/tags/jquery.tagsinput.css" />
		<script type="text/javascript" charset="utf-8" src="{__Tpl_style__}/style/tags/jquery.tagsinput.js"></script>
		{include="edit"}
    </head>
    
    <body>
	 <div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>{$molds['name']}管理</cite></a>
             
			 <a><cite>修改{$molds['name']}</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="iconfont" style="line-height:30px">&#xe6aa;</i></a>
        </div>
        <div class="x-body">
            <form class="layui-form  layui-form-pane" >
			<input type="hidden" name="go" value="1" />
			<input type="hidden" name="id" value="{$data['id']}" />
			
			<div class="layui-tab">
			  <ul class="layui-tab-title">
				<li class="layui-this">基本信息</li>
				<li>扩展信息</li>
				
			  </ul>
			  <div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
				 <div class="layui-form-item">
                    <label for="title" class="layui-form-label">
                        <span class="x-red">*</span>标题
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="title" value="{$data['title']}" style="width:500px;"  name="title" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
				{if($molds['isclasstype']==1)}
				<div class="layui-form-item">
                    <label for="tid" class="layui-form-label">
                        <span class="x-red">*</span>栏目
                    </label>
                    <div class="layui-input-inline">
					<select name="tid" lay-search="" lay-filter="tid" {if($molds['ismust']==1)}lay-verify="required"{/if} id="tid" >
					   {if($molds['ismust']==1)}
						<option value="">选择栏目</option>
						{else}
						<option value="0">不限栏目</option>
						{/if}
					   {foreach $classtypes as $v}
					   {if($v['molds']=='product')}
					   {if($admin['classcontrol']==0 || $admin['isadmin']==1 || strpos($tids,','.$v['id'].',')!==false || $molds['iscontrol']==0)}
					   <option {if($data['tid']==$v['id'])} selected="selected" {/if}  value="{$v['id']}">{fun str_repeat('--', $v['level'])}{$v['classname']}</option>
					   {/if}
					   {/foreach}
					   {/if}
					   
					</select>
                    </div>
                </div>
				{else}
				<input type="hidden" name="tid" value="{$data['tid']}" />
				{/if}
				 <div class="layui-form-item">
                    <label for="seo_title" class="layui-form-label">
                        <span class="x-red"></span>SEO标题
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="seo_title" value="{$data['seo_title']}" style="width:500px;"  name="seo_title" 
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
				<div class="layui-form-item">
                    <label for="hits" class="layui-form-label">
                        <span class="x-red"></span>点击量
                    </label>
                    <div class="layui-input-inline">
                        <input type="number" id="hits" value="{$data['hits']}" name="hits" 
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
				<div class="layui-form-item">
                    <label for="keywords" class="layui-form-label">
                        <span class="x-red"></span>关键词
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="keywords" value="{$data['keywords']}" style="width:500px;"  name="keywords" 
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
				<div class="layui-form-item">
                    <label for="price" class="layui-form-label">
                        <span class="x-red"></span>价格
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="price" value="{$data['price']}" name="price" 
                        autocomplete="off" class="layui-input">
                    </div>
				</div>
				<div class="layui-form-item">
                    <label for="stock_num" class="layui-form-label">
                        <span class="x-red"></span>库存
                    </label>
                    <div class="layui-input-inline">
                        <input type="number" id="stock_num" value="{$data['stock_num']}" name="stock_num" 
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
				<div class="layui-form-item">
                    <label for="litpic" class="layui-form-label">
						<span class="x-red"></span>首图  
                    </label>
                    
					<div class="layui-input-inline">
						<input name="litpic" placeholder="上传图片" type="text" class="layui-input" id="litpic"  value="{$data['litpic']}" />
					</div>
					<div class="layui-input-inline">
						<button class="layui-btn layui-btn-primary" id="litpic_upload" type="button" >选择图片</button>
					</div>
					<div class="layui-input-inline">
						<img id="litpic_img" class="img-responsive img-thumbnail" style="max-width: 200px;" src="{$data['litpic']}" onerror="javascipt:this.src='{__Tpl_style__}/style/images/nopic.jpg'; this.title='图片未找到';this.onerror=''">
						<button type="button" onclick="deleteImage(this)" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-danger " title="删除这张图片" >删除</button>
					</div>
                </div>
				
				<fieldset class="layui-elem-field">
				  <legend>图集</legend>
				  <div class="layui-field-box">
					  <div class="layui-input-block">
						  <div class="site-demo-upbar">
							<button type="button" class="layui-btn" id="LAY_pictures_upload">
							  <i class="layui-icon">&#xe67c;</i>上传图片
							</button>
							 可以一次选择多张图片同时上传
						  </div>
						   
					  </div>
					 
					  <div class="layui-input-block">
					  <span class="preview_pictures" >
					  {if($data['pictures']!='')}
						{foreach explode('||',$data['pictures']) as $vv}
						{if($webconf['ispicsdes']==1)}
						{php $pic = explode('|',$vv); /}
						<div class="upload-icon-img layui-input-inline" ><div class="upload-pre-item"><img src="{$pic[0]}" class="img" width="200px" height="200px" ><input name="pictures_urls[]" type="text" class="layui-input"  value="{$pic[0]}" /><input name="pictures_des[]" type="text" class="layui-input" placeholder="文字描述"  value="{$pic[1]}" /><a class="layui-btn layui-btn-sm layui-btn-radius layui-btn-danger delete_file">删除</a><a class="layui-btn layui-btn-sm layui-btn-radius imgorder " onclick="goleft(this)">左移</a><a class="layui-btn layui-btn-sm layui-btn-radius imgorder " onclick="goright(this)">右移</a></div></div>
						{else}
						<div class="upload-icon-img layui-input-inline" ><div class="upload-pre-item"><img src="{$vv}" class="img" width="200px" height="200px" ><input name="pictures_urls[]" type="text" class="layui-input"  value="{$vv}" /><a class="layui-btn layui-btn-sm layui-btn-radius layui-btn-danger delete_file">删除</a><a class="layui-btn layui-btn-sm layui-btn-radius imgorder " onclick="goleft(this)">左移</a><a class="layui-btn layui-btn-sm layui-btn-radius imgorder " onclick="goright(this)">右移</a></div></div>
						{/if}
						{/foreach}
					  {/if}	 
					  </span>
					  </div>
				  </div>
				</fieldset>
				
				
				
				 <div class="layui-form-item layui-form-text">
                        <label for="description" class="layui-form-label">
                            <span class="x-red"></span>简介
                        </label>
                        <div class="layui-input-block">
                            <textarea  name="description" class="layui-textarea">{$data['description']}</textarea>
                        </div>
                </div>
				 
				<div class="layui-form-item layui-form-text">
                    <label for="body" class="layui-form-label">
                        <span class="x-red"></span>内容
                    </label>
                    <div class="layui-input-block" style="clear:both;" >
					{include="content"}
                    </div>
                </div>
				
				{if($webconf['isrelative']==1)}
				<span id="ext_fields"></span>
				{/if}
			

				</div>
				<div class="layui-tab-item">
				{if($webconf['isrelative']==0)}
				<span id="ext_fields"></span>
				{/if}
					<div class="layui-form-item">
                    <label for="orders" class="layui-form-label">
                        <span class="x-red"></span>排序
                    </label>
                    <div class="layui-input-inline">
                        <input type="number" id="orders" value="{$data['orders']}" name="orders" 
                        autocomplete="off" class="layui-input">
                    </div>
					 <div class="layui-form-mid layui-word-aux">
					  数字越大越靠前
				  </div>
					
                </div>
				
				<div class="layui-form-item" pane>
                    <label for="tjsx" class="layui-form-label">
                        <span class="x-red"></span>推荐属性
                    </label>
                    <div class="layui-input-inline">
                        <input type="checkbox" name="istop" value="1" title="置顶" {if($data['istop']==1)}checked{/if}>
						<input type="checkbox" name="ishot" value="1" title="热点" {if($data['ishot']==1)}checked{/if}>
						<input type="checkbox" name="istuijian" value="1" title="推荐" {if($data['istuijian']==1)}checked{/if}>
                    </div>
					 
					
                </div>
				
				<div class="layui-form-item layui-form-text">
                    <label for="tags" class="layui-form-label">
                        <span class="x-red"></span>TAG标签 [ 按Enter回车自动添加 ]
                    </label>
                    <div class="layui-input-block">
                       
						 <input id="tags" type="text" class="tags" name="tags" value="{fun trim($data['tags'],',')}"  autocomplete="off" class="layui-input"  />
                    </div>
                </div>
				
				{if($admin['isadmin']==1 || ($admin['isadmin']!=1 && $admin['ischeck']==0))}
				<div class="layui-form-item" pane>
                    <label for="isshow" class="layui-form-label">
                        <span class="x-red"></span>是否审核
                    </label>
                    <div class="layui-input-block">
                        <input type="radio" name="isshow" value="0" title="未审" {if($data['isshow']==0)}checked{/if}>
						<input type="radio" name="isshow" value="1" title="已审" {if($data['isshow']==1)}checked{/if}>
						<input type="radio" name="isshow" value="2" title="退回" {if($data['isshow']==2)}checked{/if}>
                    </div>
					 
					
                </div>
				{/if}
				
				 <div class="layui-form-item" >
                    <label for="addtime" class="layui-form-label">
                        <span class="x-red"></span>更新时间
                    </label>
                    <div class="layui-input-inline">
                      <input class="layui-input" value="{if($data)}{fun date('Y-m-d H:i:s',$data['addtime'])}{else}{fun date('Y-m-d H:i:s')}{/if}" name="addtime" placeholder="文件日期" id="product_addtime">
                    </div>
                   
                </div>
				
				<div class="layui-form-item">
                    <label for="target" class="layui-form-label">
                        <span class="x-red"></span>外链URL
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="target" value="{$data['target']}" name="target" 
                        autocomplete="off" class="layui-input">
                    </div>
					<div class="layui-form-mid layui-word-aux">
					  默认为空，系统访问内容则直接跳转到此链接
					</div>
					
                </div>
				
				<div class="layui-form-item">
                    <label for="ownurl" class="layui-form-label">
                        <span class="x-red"></span>自定义URL
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="ownurl" value="{$data['ownurl']}" name="ownurl" 
                        autocomplete="off" class="layui-input">
                    </div>
					<div class="layui-form-mid layui-word-aux">
					  默认为空，自定义URL
					</div>
					
                </div>
				
				
				</div>
			  </div>
			</div>
               
                <div class="layui-form-item" id="jizhitj"  style="text-align:center;">
                    
                     <button  class="layui-btn" lay-filter="save" lay-submit="">
                        保存
                    </button>
                </div>
            </form>
        </div>
		<br/>
		<br/>
		<br/>
		<br/>
		<br/>
		<br/>
		<br/>
		<br/>
		<br/>
      
        <script>
		{include="fields"}
			$(function() {
			  $('#tags').tagsInput({
					width:'auto',
					defaultText:'添加一个标签',
			  });
			})
			function deleteImage(elm){
				$(elm).prev().attr("src", "{__Tpl_style__}/style/images/nopic.jpg");
				$('#litpic').val("");
			}
            layui.use(['laydate','form','layer','upload'], function(){
              $ = layui.jquery;
              var form = layui.form
              ,layer = layui.layer;
			  laydate = layui.laydate;
			  var upload = layui.upload;
			  laydate.render({
				elem: '#product_addtime', //指定元素
				type:'datetime'
			  });
              //图片上传接口
              upload.render({
			    elem: '#litpic_upload',
                url: "{fun U('Common/uploads')}" //上传接口
                ,data:{tid:function(){ return $("#tid").val();},molds:'product'}
                ,done: function(res){ //上传成功后的回调
                 
					if(res.code==0){
						 $('#litpic_img').attr('src',res.url);
						 $('#litpic').val(res.url);
					}else{
						 layer.alert(res.error, {icon: 5});
					}
                 
                }
              });
			  
			   
			   //执行实例
			  var uploadInst = upload.render({
				elem: "#LAY_pictures_upload" //绑定元素
				,url: "{fun U('Common/uploads')}" //上传接口
				,accept:"images"
				,multiple: true
				,acceptMime:"image/*"
				,before: function(obj){ 		
					layer.load(); //上传loading
				  }
				,data:{tid:function(){ return $("#tid").val();},molds:'product'}
				,done: function(res){
					layer.closeAll("loading"); //关闭loading
					if(res.code==0){
						var fileurl = $("#pictures").val();
						{if($webconf['ispicsdes']==1)}
						$(".preview_pictures").append('<div class="upload-icon-img layui-input-inline" ><div class="upload-pre-item"><img src="' + res.url + '" class="img" width="200px" height="200px" ><input name="pictures_urls[]" type="text" class="layui-input"  value="' + res.url + '" /><input name="pictures_des[]" type="text" class="layui-input"  placeholder="文字描述" value="" /><a class="layui-btn layui-btn-sm layui-btn-radius layui-btn-danger delete_file">删除</a><a class="layui-btn layui-btn-sm layui-btn-radius imgorder " onclick="goleft(this)">左移</a><a class="layui-btn layui-btn-sm layui-btn-radius imgorder " onclick="goright(this)">右移</a></div></div>');
						{else}
						$(".preview_pictures").append('<div class="upload-icon-img layui-input-inline" ><div class="upload-pre-item"><img src="' + res.url + '" class="img" width="200px" height="200px" ><input name="pictures_urls[]" type="text" class="layui-input"  value="' + res.url + '" /><a class="layui-btn layui-btn-sm layui-btn-radius layui-btn-danger delete_file">删除</a><a class="layui-btn layui-btn-sm layui-btn-radius imgorder " onclick="goleft(this)">左移</a><a class="layui-btn layui-btn-sm layui-btn-radius imgorder " onclick="goright(this)">右移</a></div></div>');
						{/if}
						
					}else{
						 layer.alert(res.error, {icon: 5});
					}
				}
				,error: function(){
				  //请求异常回调
				  layer.alert("上传异常！");
				}
			  });
			  
			  
			  
			  
			    //监听提交
              form.on('submit(save)', function(data){
                
				$.post("{fun U('editproduct')}",data.field,function(r){
					var r = JSON.parse(r);
					if(r.code==0){
					
						layer.confirm(r.msg, {
						  btn: ['返回列表','取消'] //按钮
						}, function(){
							// 获得frame索引
							{if($webconf['admintpl']=='tpl')}
							 window.location.href="{fun U('Product/productlist')}";
							{else}
							parent.location.reload();
							{/if}
						  
						}, function(){
						  
						});
					
					}else{
						layer.alert(r.msg, {icon: 5});
					}
				});
				
               
                return false;
              });
            get_fields({$data['tid']},{$data['id']});
			form.on('select(tid)', function(data){
			 
			  get_fields(data.value,{$data['id']});
			  
			  
			});
			
           
              
              
            });
        </script>
      
    </body>

</html>